package com.example.sentinel.consumer.feign;

import com.example.sentinel.common.bean.ErrorException;
import com.example.sentinel.common.bean.FailException;
import lombok.Setter;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: luojm
 * @create: 2020-09-01 14:18
 */
@Component
public class ProviderClientFallback implements ProviderClient {

    @Setter
    private Throwable cause;

    @Override
    public String getUserName() {
        if (cause instanceof FailException) {
            throw new FailException(cause.getMessage());
        } else if (cause instanceof IllegalArgumentException) {
            throw new IllegalArgumentException(cause.getMessage());
        } else {
            throw new ErrorException(cause.getMessage());
        }
    }
}
